package com.bsierp.util.tags;




import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.bsierp.business.pojo.User;
import com.bsierp.servicebean.printsverice.OrderPrintService;
import com.bsierp.servicebean.printsverice.PrintService;
import com.bsierp.util.Constants;

public class DisplayPrintContent extends TagSupport {
    
    String printType;//打印类型 用于判断需要调用哪个具体的打印对象
    public String getPrintType() {
        return printType;
    }

    public void setPrintType(String printType) {
        this.printType = printType;
    }

    String contextPath;//系统根目录
    
public String getContextPath() {
        return contextPath;
    }

    public void setContextPath(String contextPath) {
        this.contextPath = contextPath;
    }

private Log log = LogFactory.getLog(this.getClass().getName());

public int doEndTag() throws JspException
{
   
JspWriter out = pageContext.getOut();
HttpSession ses = pageContext.getSession();

String printType=this.printType;
String[] id=(String[])ses.getAttribute(printType+"_data");
User   u=(User)ses.getAttribute(Constants.userLogin_sessionindex);
String printString="No data to print!";
try{
    PrintService ps=null;
    if(printType.equals("order")){
        ps=new OrderPrintService();
    }
    printString= ps.getPrintStr(id, u,this.contextPath);
    out.print(printString);
   
}catch (Exception ex)
{
    ex.printStackTrace();
  throw new JspTagException("IOException:" + ex.toString());
}
return super.doEndTag();
}
}


